<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class article extends CI_Controller{
    //put your code here
    function __construct() {
        parent::__construct();
        /*
        $this->Cache_model->setLang($this->input->get());
        
        $this->Lang_model->loadLang('front',$this->Cache_model->currentLang);
        if($this->uri->segment(1)){
                show_404();
        }
        $this->load->helper('tags');
         * 
         */
    }
    
    public function index(){
        //$id = $_REQUEST['id'];
        //$this->articleList($id);
        $this->load->model();
    }
    
    public function articleAll(){
        $this->load->library('calendar');
        $key = $this->input->get();
        $this->load->setPath();
        $config['site_template'] = 'zjqas'; 
        $config['site_templateurl'] = base_url('/data/template').'/'.$config['site_template'];
        $listall = array();
        if($key['searchKey']){
            $listall = $this->search($key['searchKey']);
        }else{
            $listall = $this->Data_model->getData(array(),'',0,0,'article');
        }
        $new_list = array();
        $i = 1;
        foreach ($listall as $value) {
            $value['lid'] = $i;
            $i++;
            array_push($new_list, $value);
        }
        $catalog = array();
        $res = array(
            'config'  => $config,
            'list'    => $new_list,
            'catalog' => $catalog
        );
        $this->load->view($config['site_template'].'/projectList',$res);
    }

    public function articleList(){
        $this->load->setPath();
        $id = $this->input->get();
        $config['site_template'] = 'zjqas'; 
        $config['site_templateurl'] = base_url('/data/template').'/'.$config['site_template'];
        $list = $this->Data_model->getData(array('category' => $id),'',0,0,'article');
        $catalog = $this->getCatalog($id);
        $new_list = array();
        $i = 1;
        foreach ($list as $value) {
            $value['lid'] = $i;
            $i++;
            array_push($new_list, $value);
        }
        
        $res = array(
            'config'  => $config,
            'list'    => $new_list,
            'catalog' => $catalog
        );
        $this->load->view($config['site_template'].'/projectList',$res);
    }
    
    public function articleContent(){
        $id = $this->input->get();
        $data = $this->Data_model->getSingle(array('id' => $id),'article');
        echo json_encode($data);
    }
    
    public function getCatalog($id = ""){
        $catalog = $this->Data_model->getSingle(array('id' => $id),'category');
        return $catalog;
    }
    
    public function search($key = ''){
        $this->load->setPath();
        $config['site_template'] = 'zjqas'; 
        $config['site_templateurl'] = base_url('/data/template').'/'.$config['site_template'];
        $sql = "select * from lee_article where title like '%$key%' or description like '%$key%' or content like '%$key%'";
        $query = $this->db->query($sql);
        $data = $query->result_array();
        return $data;
    }
    //test data 
}
